<template>
  <div class="div-style" style="padding: 10px">
    <el-row :gutter="5">
      <el-col :span="11">
        <apply-form
          :inorout-flag="props.inoroutFlag"
          :org-id="userInfo.orgId"
          @submit-form-ok="labItemRefresh"
          :patient-id="patientId"
        />
      </el-col>
      <el-col :span="13">
        <apply-table
          ref="applyTableRef"
          :inorout-flag="props.inoroutFlag"
          :org-id="userInfo.orgId"
        />
      </el-col>
    </el-row>
  </div>
</template>
<script lang="ts">
export default {
  name: "LabApply",
};
</script>

<script lang="ts" setup>
import { delLabApply } from "@/api/patient/labApply";
import applyTable from "./applyTable.vue";
import applyForm from "./applyForm.vue";
import { useDictStoreHook } from "@/store/modules/dict";
import { useUserStoreHook } from "@/store/modules/user";

const useUserStore = useUserStoreHook();
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo;
const dictStore = useDictStoreHook();
let dictDataMap = ref(dictStore.isTypeGetData("clinic_or_visit"));
const { proxy } = getCurrentInstance() as any;
const patientId = ref(proxy.$patientId)
const props = defineProps({
  inoroutFlag: {
    type: String,
    default: "",
  },
});
const formRef = ref();
const applyTableRef = ref();
const queryParamsRef = ref();
const labApplyList = ref([]);
const open = ref(false);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const queryParams = ref<any>({
  pageNum: 1,
  pageSize: 10,
  clinicId: "",
  applyDept: "",
  applyUserName: "",
  applyNo: "",
  patientId: "",
  inoroutFlag: "",
  confirmFlag: "",
  confirmUser: "",
  cancelConfirmUser: "",
  chargeFlag: "",
  implementDept: "",
  isUrgent: "",
  specimen: "",
  specimenExplain: "",
  orgId: "",
  remarks: "",
  visitId: "",
  ordersId: "",
  isPhy: "",
  resultStatus: "",
  resultsRptDateTime: "",
  transcriptionist: "",
  naYaoTiShi: "",
  jianYi: "",
  sampleId: "",
  auditor: "",
  notes: "",
  confirmDate: "",
  confirmCancelFlag: "",
  realDate: "",
  symptom: "",
  sign: "",
  clinicalDiag: "",
  relevantDiag: "",
  relevantResult: "",
});
/** 查询检查申请主列表 */
// function getList() {
//   loading.value = true;
//   listLabApply(queryParams.value).then((response: any) => {
//     labApplyList.value = response.rows;
//     total.value = response.total;
//     loading.value = false;
//   });
// }
/** 检查列表刷新 */
function labItemRefresh() {
  nextTick(() => {
    applyTableRef.value.getList();
  });
}

/** 取消loading */

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  // getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParamsRef.value.resetFields();
  // proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  ElMessageBox.confirm('是否确认删除检查申请主编号为"' + ids + '"的数据项？', {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      delLabApply(_ids).then(() => {
        // getList();
        ElMessage.success("删除成功");
      });
    })
    .catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "business/labApply/export",
    {
      ...queryParams.value,
    },
    `labApply_${new Date().getTime()}.xlsx`
  );
}

defineExpose({
    labItemRefresh
})
// getList();
</script>
